#include "Card.h"

namespace core
{

Card::Card()
	: mRank(0)
	, mSuit(0)
{
}

Card::Card(uint8 rnk, uint8 s)
	: mRank(rnk)
	, mSuit(s)
{
}


bool Card::operator== (const Card& right)
{
	return (mRank == right.rank());
}

bool Card::operator>  (const Card& right)
{
	return mRank > right.rank();
}


std::ostream& operator<< (std::ostream &output, Card obj)
{
	switch (obj.rank())
	{
	case 2:
	case 3:
	case 4:
	case 5:
	case 6:
	case 7:
	case 8:
	case 9:
		output << obj.rank();
		break;
	case 10:
		output << 'T';
		break;
	case 11:
		output << 'J';
		break;
	case 12:
		output << 'Q';
		break;
	case 13:
		output << 'K';
		break;
	case 14:
		output << 'A';
		break;
	default:
		output.clear();
		output << "\nINVALID CARD'S RANK\n";
		return output;
	}

	switch (obj.suit())
	{
	case SPADES:
		output << 's';
		break;
	case CLUBS:
		output << 'c';
		break;
	case DIAMONDS:
		output << 'd';
		break;
	case HEARTS:
		output << 'h';
		break;
	default:
		output.clear();
		output << "\nINVALID CARD'S SUIT\n";
		return output;
	}

	return output;
}

Card::Card(bool input)
{
	if (input)
	{
		char value[3];
		std::cin.getline(value, 3);

		switch (value[0])
		{
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			mRank = value[0] - '2' + 2;
			break;
		case 'T':
			mRank = 10;
			break;
		case 'J':
			mRank = 11;
			break;
		case 'Q':
			mRank = 12;
			break;
		case 'K':
			mRank = 13;
			break;
		case 'A':
			mRank = 14;
			break;
		default:
			mRank = 0;
			break;
		}

		switch (value[1])
		{
		case 's':
			mSuit = SPADES;
			break;
		case 'c':
			mSuit = CLUBS;
			break;
		case 'd':
			mSuit = DIAMONDS;
			break;
		case 'h':
			mSuit = HEARTS;
			break;
		default:
			mRank = 0;
			mSuit = 0;
		}
	}
}

} // namespace core